const fs = require('fs')

function readdir (path, list) {

    let files = fs.readdirSync(path)

    for (const fileName of files) {
        let filePath = path + fileName

        if (fileName.startsWith('.')) {
            continue
        }

        let fileStat = fs.statSync(filePath)
        if (fileStat.isFile()) {
            list.push({
                name: fileName,
                path: filePath,
                modifyAt: fileStat.mtime
            })
        } else {
            readdir(filePath + '/', list)
        }
    }

}

exports.read = function (path) {
    let list = []
    readdir(path, list)
    return list
}